import filterEmpty from './filterEmpty';
const filterDataToRemoteFilter = (data) => {
  const { filters } = data;
  let nestData = {};
  // 将 ui 的 filter 转成后端的 filter
  for (let i = 0; i < filters.length; i++) {
    const section = filters[i];
    const nextSection = {
      type: 'or',
      filters: section.filters,
    };
    if (i === 0) {
      nestData = nextSection;
    } else {
      nestData = {
        type: filters[i - 1].type,
        filters: [nestData, nextSection],
      };
    }
  }
  return filterEmpty(nestData);
};

export default filterDataToRemoteFilter;
